import 'package:flutter/widgets.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lib_uikit/widgets/gt_toast_native.dart';

extension StringExtension on String? {

  void errorToast([BuildContext? context]) {
    GTToast().showToast(context, ToastLevel.error, this);
  }

  void infoToast([BuildContext? context]) {
    GTToast().showToast(context, ToastLevel.info, this);
  }

  void successToast([BuildContext? context]) {
    GTToast().showToast(context, ToastLevel.success, this);
  }

  void warnToast([BuildContext? context]) {
    GTToast().showToast(context, ToastLevel.warning, this);
  }
}

extension StringExtensionV3 on String? {

  void errorToastV3([BuildContext? context]) {
    GTToastV3().showToast(context, ToastLevel.error, this);
  }

  void infoToastV3([BuildContext? context]) {
    GTToastV3().showToast(context, ToastLevel.info, this);
  }

  void successToastV3([BuildContext? context]) {
    GTToastV3().showToast(context, ToastLevel.success, this);
  }

  void warnToastV3([BuildContext? context]) {
    GTToastV3().showToast(context, ToastLevel.warning, this);
  }

  Color changeRiseAndFallColor({Color? defaultColor}) {
    double value = double.tryParse(this ?? '0') ?? 0;

    if (value == 0) {
      return defaultColor ?? GTColorsV3.uikitPd2V3.color;
    }

    bool isRise = value > 0;
    if (GTThemeProvider.instance.isHzld()) {
      return isRise ? GTColorsV3.uikitPd1V3.color : GTColorsV3.uikitPd2V3.color;
    }
    return isRise ? GTColorsV3.uikitPd2V3.color : GTColorsV3.uikitPd1V3.color;
  }
}

extension StringExtensionNative on String? {
  void errorToastNative() {
    GTNativeToast.showToast(ToastLevel.error, this);
  }

  void infoToastNative() {
    GTNativeToast.showToast(ToastLevel.info, this);
  }

  void successToastNative() {
    GTNativeToast.showToast(ToastLevel.success, this);
  }

  void warnToastNative() {
    GTNativeToast.showToast(ToastLevel.warning, this);
  }
}
